<?php

     
      header("Access-Control-Allow-Origin:*");
      require "./connect_mySQL.php";
      $username = @$_POST["username"];
      $password = @$_POST["password"];
      // $cookie = @$_COOKIE["tocken"];
      $author = $_POST["author"];

      // echo "1231231   $cookie  qqq";
      // if($cookie){
      //       echo "vvvvvv"
      // }

      if($username === "" || $password === ""){
            die("账号密码均不能为空");
      }

      if(!in_array($author, $tb_list)){
            $json_arr = array( "status" => "error" , "stateCode" => "4" , "errorType" => "author is error");
            die(json_encode($json_arr));
      }
      createTable($con,$author);

      $select_SQL = "SELECT username,password FROM $author";
      
      $select_res = mysql_query($select_SQL,$con);

      if($select_res){

            // if($cookie){
            //       $password = $cookie;
            // }else{
            //       $password = md5($password);
            // }
            $pwd = $password;
            $password = md5($password);

            while($row = mysql_fetch_array($select_res)){
                  if($row["username"] === $username && ($row["password"] ===  $password || $row["password"] ===  $pwd)){
                        mysql_close($con);
                        $json_arr = array( "status" => "success" , "stateCode" => "1");
                        die(json_encode($json_arr));
                  }
            }
      }
      mysql_close($con);
      $json_arr = array( "status" => "error" , "stateCode" => "6", "errorType" => "User name password mismatch");
      echo json_encode($json_arr);
?>